package com.blog4j.user.api.inner;

import com.blog4j.api.client.FeignUser;
import com.blog4j.api.vo.MessageVo;
import com.blog4j.api.vo.OrganizationVo;
import com.blog4j.api.vo.RoleInfoVo;
import com.blog4j.api.vo.UserIllegalRecordVo;
import com.blog4j.api.vo.UserInfoVo;
import com.blog4j.api.vo.EditUserLastLoginTimeReqVo;
import com.blog4j.api.vo.PermissionVo;
import com.blog4j.user.service.FansService;
import com.blog4j.user.service.OrganizationService;
import com.blog4j.user.service.PermissionService;
import com.blog4j.user.service.RoleService;
import com.blog4j.user.service.UserIllegalRecordService;
import com.blog4j.user.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
 * @author 98k灬
 * @version v1.0.0
 * @Description : 功能描述
 * @Create on : 2024/7/18 21:10
 **/
@RestController
@RequestMapping("/feign")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class UserFeignController implements FeignUser {
    private final UserService userService;
    private final OrganizationService organizationService;
    private final PermissionService permissionService;
    private final RoleService roleService;
    private final FansService fansService;
    private final UserIllegalRecordService userIllegalRecordService;

    /**
     * 根据用户名获取用户信息
     *
     * @param userName 用户名
     * @return 用户信息
     */
    @GetMapping("/getUserInfoByUserName/{userName}")
    public UserInfoVo getUserInfoByUserName(@PathVariable("userName") String userName) {
        return userService.getUserInfoByUserName(userName);
    }

    /**
     * 根据用户ID获取组织信息
     *
     * @param userId 用户ID
     * @return 组织信息
     */
    @GetMapping("/getOrganizationInfoByUserId/{userId}")
    public List<OrganizationVo> getOrganizationInfoByUserId(@PathVariable("userId") String userId) {
        return organizationService.getOrganizationInfoByUserId(userId);
    }

    /**
     * 根据组织管理员ID获取该组织下所有的用户ID列表
     *
     * @param admins@return 组织下所有的用户ID列表
     */
    @Override
    public List<String> getUserIdsByOrganizationAdmin(List<String> admins) {
        return organizationService.getUserIdsByOrganizationAdmin(admins);
    }

    /**
     * 根据用户ID获取用户信息
     *
     * @param userId 用户ID
     * @return 用户信息
     */
    @GetMapping("/getUserInfoByUserId/{userId}")
    public UserInfoVo getUserInfoByUserId(@PathVariable("userId") String userId) {
        return userService.getUserInfoByUserId(userId);
    }

    /**
     * 根据用户ID获取权限信息
     *
     * @param userId 用户ID
     * @return 权限信息
     */
    @GetMapping("/getPermissionListByUserId/{userId}")
    public List<PermissionVo> getPermissionListByUserId(@PathVariable("userId") String userId) {
        return permissionService.getPermissionListByUserId(userId);
    }

    /**
     * 更新用户的最近一次登录时间
     *
     * @param reqVo 请求信息
     */
    @PostMapping("/updateUserLastLoginTime")
    public void updateUserLastLoginTime(@RequestBody @Valid EditUserLastLoginTimeReqVo reqVo) {
        userService.updateUserLastLoginTime(reqVo);
    }

    /**
     * 根据用户ID获取角色信息
     *
     * @param userId 用户ID
     * @return 角色信息
     */
    @GetMapping("/getRoleInfoByUserId/{userId}")
    public RoleInfoVo getRoleInfoByUserId(@PathVariable("userId") String userId) {
        return roleService.getRoleInfoByUserId(userId);
    }

    /**
     * 根据手机号码查询用户信息
     *
     * @param phone 手机号码
     * @return 用户信息
     */
    @Override
    public UserInfoVo getUserInfoByPhone(String phone) {
        return userService.getUserInfoByPhone(phone);
    }

    /**
     * 根据用户的映射ID获取用户信息
     *
     * @param id 用户的映射ID
     * @return 用户信息
     */
    @Override
    public UserInfoVo getUserInfoById(Integer id) {
        return userService.getUserInfoById(id);
    }

    /**
     * 根据用户ID获取粉丝列表
     *
     * @param userId 用户ID
     * @return 粉丝列表
     */
    @Override
    public List<UserInfoVo> getFansListByUserId(String userId) {
        return fansService.getFansListByUserId(userId);
    }

    /**
     * 用户个数
     *
     * @return 用户个数
     */
    @Override
    public Integer userCount() {
        return userService.userCount();
    }

    /**
     * 组织个数
     *
     * @return 组织个数
     */
    @Override
    public Integer organizationCount() {
        return organizationService.organizationCount();
    }

    /**
     * 根据用户ID获取组织信息
     *
     * @param userIds 用户ID集合
     * @return 组织信息
     */
    @Override
    public Map<String, List<OrganizationVo>> getOrganizationListInfoByUserId(List<String> userIds) {
        return organizationService.getOrganizationListInfoByUserId(userIds);
    }

    /**
     * 根据组织ID获取组织信息列表
     *
     * @param organizationIds 组织ID
     * @return 组织信息列表
     */
    @Override
    public List<OrganizationVo> getOrganizationListByIds(List<String> organizationIds) {
        return organizationService.getOrganizationListByIds(organizationIds);
    }

    /**
     * 获取超级管理员信息
     *
     * @return 超级管理员信息
     */
    @Override
    public UserInfoVo getSuperAdminInfo() {
        return userService.getSuperAdminInfo();
    }

    /**
     * 发送消息
     *
     * @param messageVo 消息
     */
    @Override
    public void sendMessage(MessageVo messageVo) {
        userService.sendMessage(messageVo);
    }

    /**
     * 添加用户不合法记录
     *
     * @param userIllegalRecordVo 用户不合法记录请求体
     */
    @Override
    public void addUserIllegalRecord(UserIllegalRecordVo userIllegalRecordVo) {
        userIllegalRecordService.addUserIllegalRecord(userIllegalRecordVo);
    }
}
